package socdev.mobile;

import java.util.List;

import socdev.data.Commit;
import socdev.data.User;
import socdev.mobile.CommitsAdapter.CommitHolder;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class TeamUsersAdapter  extends ArrayAdapter<User>{

		Context context;
		int layoutResourceId;
		List<User> data;
		public TeamUsersAdapter(Context context, int textViewResourceId, List<User> data) {
			super(context, textViewResourceId, data);
			this.context = context;
			this.layoutResourceId = textViewResourceId;
			this.data = data;
		}
		
		@Override
	    public View getView(int position, View convertView, ViewGroup parent) {
	        View row = convertView;
	        UserHolder holder = null;
	        
	        if(row == null)
	        {
	            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
	            row = inflater.inflate(layoutResourceId, parent, false);
	            
	            holder = new UserHolder();
	            holder.nick = (TextView)row.findViewById(R.id.nick);
	            holder.description = (TextView)row.findViewById(R.id.description);
	            holder.role = (TextView)row.findViewById(R.id.role);
	            
	            row.setTag(holder);
	        }
	        else
	        {
	            holder = (UserHolder)row.getTag();
	        }
	        
	        User user = data.get(position);
	        
	        holder.nick.setText(user.nick);
	        holder.description.setText(user.description);
	        holder.role.setText(user.role);
	        return row;
	    }
		
		static class UserHolder
	    {
	        TextView nick;
	        TextView description;
	        TextView role;
	    }
		
	}
